package com.itheima.controller;

import com.itheima.common.Result;
import com.itheima.dto.UserLoginDTO;
import com.itheima.service.IndexService;
import com.itheima.vo.ConfigVO;
import com.itheima.vo.HomeVO;
import com.itheima.vo.ProfileVO;
import com.itheima.vo.UserLoginVO;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;


/**
 * 索引控制器
 *
 * @author 13225
 * @date 2023/09/21
 */
@RestController
@RequestMapping("/index")
@RequiredArgsConstructor
@Slf4j
public class IndexController {

    private final IndexService indexService;

    /**
     * 登录
     *
     * @param userLoginDTO 用户登录dto
     * @return {@link Result}<{@link ?}>
     */
    @PostMapping("/login")
    public Result<?> login(@RequestBody UserLoginDTO userLoginDTO) {
        UserLoginVO userLoginVO = indexService.login(userLoginDTO);
        log.info("数据是-->{}",userLoginVO);
        return Result.success(userLoginVO);
    }

    /**
     * 获取首页登录数据
     *
     * @return {@link Result}<{@link ?}>
     */
    @PostMapping("/profile")
    public Result<?> profile() {
        ProfileVO profileVO = indexService.profile();
        log.info("数据是-->{}",profileVO);
        return Result.success(profileVO);
    }

    /**
     * 获取配置
     *
     * @return {@link Result}<{@link ?}>
     */
    @GetMapping("/getConfig")
    public Result<?> getConfig(){
        ConfigVO configVO = indexService.getConfig();
        return Result.success(configVO);
    }

    /**
     * 基本信息配置
     *
     * @return {@link Result}<{@link ?}>
     */
    @GetMapping("/baseInfo")
    public Result<?> baseInfoConfig() {
        HomeVO homeVO = indexService.baseInfoConfig();
        return Result.success(homeVO);
    }
}
